//============================================================================================
/**
 * @file	mb_bmp.c
 * @brief	メールボックス画面 BMP関連
 * @author	Hiroyuki Nakamura
 * @date	09.01.31
 */
//============================================================================================
#include "common.h"

#include "gflib/strbuf_family.h"
#include "system/fontproc.h"
#include "msgdata/msg_mailbox_app.h"

#include "mb_main.h"
#include "mb_bmp.h"


//============================================================================================
//	定数定義
//============================================================================================

// BMPWIN定義
// メールリスト
#define	BMPWIN_MAIL_FRM		( MBMAIN_BGF_BTN_M )
#define	BMPWIN_MAIL_PX		( 4 )
#define	BMPWIN_MAIL_PY		( 1 )
#define	BMPWIN_MAIL_SX		( 8 )
#define	BMPWIN_MAIL_SY		( 2 )
#define	BMPWIN_MAIL_PAL		( 1 )
#define	BMPWIN_MAIL01_CGX	( 1024 - BMPWIN_MAIL_SX * BMPWIN_MAIL_SY )
#define	BMPWIN_MAIL02_CGX	( BMPWIN_MAIL01_CGX - BMPWIN_MAIL_SX * BMPWIN_MAIL_SY )
#define	BMPWIN_MAIL03_CGX	( BMPWIN_MAIL02_CGX - BMPWIN_MAIL_SX * BMPWIN_MAIL_SY )
#define	BMPWIN_MAIL04_CGX	( BMPWIN_MAIL03_CGX - BMPWIN_MAIL_SX * BMPWIN_MAIL_SY )
#define	BMPWIN_MAIL05_CGX	( BMPWIN_MAIL04_CGX - BMPWIN_MAIL_SX * BMPWIN_MAIL_SY )
#define	BMPWIN_MAIL06_CGX	( BMPWIN_MAIL05_CGX - BMPWIN_MAIL_SX * BMPWIN_MAIL_SY )
#define	BMPWIN_MAIL07_CGX	( BMPWIN_MAIL06_CGX - BMPWIN_MAIL_SX * BMPWIN_MAIL_SY )
#define	BMPWIN_MAIL08_CGX	( BMPWIN_MAIL07_CGX - BMPWIN_MAIL_SX * BMPWIN_MAIL_SY )
#define	BMPWIN_MAIL09_CGX	( BMPWIN_MAIL08_CGX - BMPWIN_MAIL_SX * BMPWIN_MAIL_SY )
#define	BMPWIN_MAIL10_CGX	( BMPWIN_MAIL09_CGX - BMPWIN_MAIL_SX * BMPWIN_MAIL_SY )
#define	BMPWIN_MAIL11_CGX	( BMPWIN_MAIL10_CGX - BMPWIN_MAIL_SX * BMPWIN_MAIL_SY )
#define	BMPWIN_MAIL12_CGX	( BMPWIN_MAIL11_CGX - BMPWIN_MAIL_SX * BMPWIN_MAIL_SY )
#define	BMPWIN_MAIL13_CGX	( BMPWIN_MAIL12_CGX - BMPWIN_MAIL_SX * BMPWIN_MAIL_SY )
#define	BMPWIN_MAIL14_CGX	( BMPWIN_MAIL13_CGX - BMPWIN_MAIL_SX * BMPWIN_MAIL_SY )
#define	BMPWIN_MAIL15_CGX	( BMPWIN_MAIL14_CGX - BMPWIN_MAIL_SX * BMPWIN_MAIL_SY )
#define	BMPWIN_MAIL16_CGX	( BMPWIN_MAIL15_CGX - BMPWIN_MAIL_SX * BMPWIN_MAIL_SY )
#define	BMPWIN_MAIL17_CGX	( BMPWIN_MAIL16_CGX - BMPWIN_MAIL_SX * BMPWIN_MAIL_SY )
#define	BMPWIN_MAIL18_CGX	( BMPWIN_MAIL17_CGX - BMPWIN_MAIL_SX * BMPWIN_MAIL_SY )
#define	BMPWIN_MAIL19_CGX	( BMPWIN_MAIL18_CGX - BMPWIN_MAIL_SX * BMPWIN_MAIL_SY )
#define	BMPWIN_MAIL20_CGX	( BMPWIN_MAIL19_CGX - BMPWIN_MAIL_SX * BMPWIN_MAIL_SY )
// 選択メール
#define	BMPWIN_SELMAIL_FRM	( MBMAIN_BGF_STR_M )
#define	BMPWIN_SELMAIL_PX	( 4 )
#define	BMPWIN_SELMAIL_PY	( 1 )
#define	BMPWIN_SELMAIL_SX	( BMPWIN_MAIL_SX )
#define	BMPWIN_SELMAIL_SY	( BMPWIN_MAIL_SY )
#define	BMPWIN_SELMAIL_PAL	( BMPWIN_MAIL_PAL )
#define	BMPWIN_SELMAIL_CGX	( 1024 - BMPWIN_SELMAIL_SX * BMPWIN_SELMAIL_SY )
//「やめる」
#define	BMPWIN_RET_FRM		( MBMAIN_BGF_STR_M )
#define	BMPWIN_RET_PX		( 25 )
#define	BMPWIN_RET_PY		( 21 )
#define	BMPWIN_RET_SX		( 6 )
#define	BMPWIN_RET_SY		( 2 )
#define	BMPWIN_RET_PAL		( 15 )
#define	BMPWIN_RET_CGX		( BMPWIN_SELMAIL_CGX - BMPWIN_RET_SX * BMPWIN_RET_SY )
//「とじる」
#define	BMPWIN_CLOSE_FRM	( MBMAIN_BGF_STR_M )
#define	BMPWIN_CLOSE_PX		( 25 )
#define	BMPWIN_CLOSE_PY		( 21 )
#define	BMPWIN_CLOSE_SX		( 6 )
#define	BMPWIN_CLOSE_SY		( 2 )
#define	BMPWIN_CLOSE_PAL	( 15 )
#define	BMPWIN_CLOSE_CGX	( BMPWIN_RET_CGX - BMPWIN_CLOSE_SX * BMPWIN_CLOSE_SY )
// ページ
#define	BMPWIN_PAGE_FRM		( MBMAIN_BGF_STR_M )
#define	BMPWIN_PAGE_PX		( 10 )
#define	BMPWIN_PAGE_PY		( 21 )
#define	BMPWIN_PAGE_SX		( 5 )
#define	BMPWIN_PAGE_SY		( 2 )
#define	BMPWIN_PAGE_PAL		( 15 )
#define	BMPWIN_PAGE_CGX		( BMPWIN_CLOSE_CGX - BMPWIN_PAGE_SX * BMPWIN_PAGE_SY )
// メッセージ
#define	BMPWIN_TALK_FRM		( MBMAIN_BGF_MSG_M )
#define	BMPWIN_TALK_PX		( 2 )
#define	BMPWIN_TALK_PY		( 19 )
#define	BMPWIN_TALK_SX		( 27 )
#define	BMPWIN_TALK_SY		( 4 )
#define	BMPWIN_TALK_PAL		( MBMAIN_MBG_PAL_TALKFNT )
#define	BMPWIN_TALK_CGX		( 1 )

//「メールボックス」
#define	BMPWIN_TITLE_FRM	( MBMAIN_BGF_STR_S )
#define	BMPWIN_TITLE_PX		( 1 )
#define	BMPWIN_TITLE_PY		( 1 )
#define	BMPWIN_TITLE_SX		( 11 )
#define	BMPWIN_TITLE_SY		( 2 )
#define	BMPWIN_TITLE_PAL	( MBMAIN_SBG_PAL_SYSFNT )
#define	BMPWIN_TITLE_CGX	( 1 )
// メールの内容
#define	BMPWIN_MAILMSG_FRM	( MBMAIN_BGF_MAILMES_S )
#define	BMPWIN_MAILMSG_PX	( 3 )
#define	BMPWIN_MAILMSG_SX	( 26 )
#define	BMPWIN_MAILMSG_SY	( 4 )
#define	BMPWIN_MAILMSG_PAL	( MBMAIN_SBG_PAL_MAILMSE )
// メールの内容１
#define	BMPWIN_MAILMSG1_PY	( 3 )
#define	BMPWIN_MAILMSG1_CGX	( 1 )
// メールの内容２
#define	BMPWIN_MAILMSG2_PY	( 8 )
#define	BMPWIN_MAILMSG2_CGX	( BMPWIN_MAILMSG1_CGX + BMPWIN_MAILMSG_SX * BMPWIN_MAILMSG_SY )
// メールの内容３
#define	BMPWIN_MAILMSG3_PY	( 13 )
#define	BMPWIN_MAILMSG3_CGX	( BMPWIN_MAILMSG2_CGX + BMPWIN_MAILMSG_SX * BMPWIN_MAILMSG_SY )
// 作成者名
#define BMPWIN_NAME_FRM		( MBMAIN_BGF_MAILMES_S )
#define BMPWIN_NAME_PX		( 21 )
#define BMPWIN_NAME_PY		( 20 )
#define BMPWIN_NAME_SX		( 8 )
#define BMPWIN_NAME_SY		( 2 )
#define BMPWIN_NAME_PAL		( MBMAIN_SBG_PAL_MAILMSE )
#define BMPWIN_NAME_CGX		( BMPWIN_MAILMSG3_CGX + BMPWIN_MAILMSG_SX * BMPWIN_MAILMSG_SY )

#define	FCOL_TCH_BLN_M01	( GF_PRINTCOLOR_MAKE( 3, 2, 0 ) )		// フォントカラー：タッチ青抜M01
#define	FCOL_TCH_RDN_M01	( GF_PRINTCOLOR_MAKE( 5, 4, 0 ) )		// フォントカラー：タッチ赤抜M01
#define	FCOL_TLK_BKW_M14	( GF_PRINTCOLOR_MAKE( 1, 2, 15 ) )		// フォントカラー：会話黒白M14
#define	FCOL_TCH_BKN_M15	( GF_PRINTCOLOR_MAKE( 15, 1, 0 ) )		// フォントカラー：タッチ黒抜M15
#define	FCOL_SYS_BKN_M15	( GF_PRINTCOLOR_MAKE( 1, 2, 0 ) )		// フォントカラー：システム黒抜M15
#define FCOL_SYS_BKN_S00	( GF_PRINTCOLOR_MAKE( 1, 2, 0 ) )		// フォントカラー：システム黒抜S00
#define	FCOL_SYS_BKN_S15	( GF_PRINTCOLOR_MAKE( 1, 2, 0 ) )		// フォントカラー：システム黒抜S15

// メッセージ表示モード
enum {
	STRPRINT_MODE_LEFT = 0,		// 左詰
	STRPRINT_MODE_RIGHT,		// 右詰
	STRPRINT_MODE_CENTER		// 中央
};


//============================================================================================
//	プロトタイプ宣言
//============================================================================================
static void MailMesPut( MAILBOX_SYS_WORK * syswk, u32 winID, u32 msgID );


//============================================================================================
//	グローバル変数
//============================================================================================

// BMPWINデータ
static const BMPWIN_DAT BmpWinData[] =
{
	// 下画面
	{	// メールリスト
		BMPWIN_MAIL_FRM, BMPWIN_MAIL_PX, BMPWIN_MAIL_PY,
		BMPWIN_MAIL_SX, BMPWIN_MAIL_SY, BMPWIN_MAIL_PAL, BMPWIN_MAIL01_CGX
	},
	{
		BMPWIN_MAIL_FRM, BMPWIN_MAIL_PX, BMPWIN_MAIL_PY,
		BMPWIN_MAIL_SX, BMPWIN_MAIL_SY, BMPWIN_MAIL_PAL, BMPWIN_MAIL02_CGX
	},
	{
		BMPWIN_MAIL_FRM, BMPWIN_MAIL_PX, BMPWIN_MAIL_PY,
		BMPWIN_MAIL_SX, BMPWIN_MAIL_SY, BMPWIN_MAIL_PAL, BMPWIN_MAIL03_CGX
	},
	{
		BMPWIN_MAIL_FRM, BMPWIN_MAIL_PX, BMPWIN_MAIL_PY,
		BMPWIN_MAIL_SX, BMPWIN_MAIL_SY, BMPWIN_MAIL_PAL, BMPWIN_MAIL04_CGX
	},
	{
		BMPWIN_MAIL_FRM, BMPWIN_MAIL_PX, BMPWIN_MAIL_PY,
		BMPWIN_MAIL_SX, BMPWIN_MAIL_SY, BMPWIN_MAIL_PAL, BMPWIN_MAIL05_CGX
	},
	{
		BMPWIN_MAIL_FRM, BMPWIN_MAIL_PX, BMPWIN_MAIL_PY,
		BMPWIN_MAIL_SX, BMPWIN_MAIL_SY, BMPWIN_MAIL_PAL, BMPWIN_MAIL06_CGX
	},
	{
		BMPWIN_MAIL_FRM, BMPWIN_MAIL_PX, BMPWIN_MAIL_PY,
		BMPWIN_MAIL_SX, BMPWIN_MAIL_SY, BMPWIN_MAIL_PAL, BMPWIN_MAIL07_CGX
	},
	{
		BMPWIN_MAIL_FRM, BMPWIN_MAIL_PX, BMPWIN_MAIL_PY,
		BMPWIN_MAIL_SX, BMPWIN_MAIL_SY, BMPWIN_MAIL_PAL, BMPWIN_MAIL08_CGX
	},
	{
		BMPWIN_MAIL_FRM, BMPWIN_MAIL_PX, BMPWIN_MAIL_PY,
		BMPWIN_MAIL_SX, BMPWIN_MAIL_SY, BMPWIN_MAIL_PAL, BMPWIN_MAIL09_CGX
	},
	{
		BMPWIN_MAIL_FRM, BMPWIN_MAIL_PX, BMPWIN_MAIL_PY,
		BMPWIN_MAIL_SX, BMPWIN_MAIL_SY, BMPWIN_MAIL_PAL, BMPWIN_MAIL10_CGX
	},
	{
		BMPWIN_MAIL_FRM, BMPWIN_MAIL_PX, BMPWIN_MAIL_PY,
		BMPWIN_MAIL_SX, BMPWIN_MAIL_SY, BMPWIN_MAIL_PAL, BMPWIN_MAIL11_CGX
	},
	{
		BMPWIN_MAIL_FRM, BMPWIN_MAIL_PX, BMPWIN_MAIL_PY,
		BMPWIN_MAIL_SX, BMPWIN_MAIL_SY, BMPWIN_MAIL_PAL, BMPWIN_MAIL12_CGX
	},
	{
		BMPWIN_MAIL_FRM, BMPWIN_MAIL_PX, BMPWIN_MAIL_PY,
		BMPWIN_MAIL_SX, BMPWIN_MAIL_SY, BMPWIN_MAIL_PAL, BMPWIN_MAIL13_CGX
	},
	{
		BMPWIN_MAIL_FRM, BMPWIN_MAIL_PX, BMPWIN_MAIL_PY,
		BMPWIN_MAIL_SX, BMPWIN_MAIL_SY, BMPWIN_MAIL_PAL, BMPWIN_MAIL14_CGX
	},
	{
		BMPWIN_MAIL_FRM, BMPWIN_MAIL_PX, BMPWIN_MAIL_PY,
		BMPWIN_MAIL_SX, BMPWIN_MAIL_SY, BMPWIN_MAIL_PAL, BMPWIN_MAIL15_CGX
	},
	{
		BMPWIN_MAIL_FRM, BMPWIN_MAIL_PX, BMPWIN_MAIL_PY,
		BMPWIN_MAIL_SX, BMPWIN_MAIL_SY, BMPWIN_MAIL_PAL, BMPWIN_MAIL16_CGX
	},
	{
		BMPWIN_MAIL_FRM, BMPWIN_MAIL_PX, BMPWIN_MAIL_PY,
		BMPWIN_MAIL_SX, BMPWIN_MAIL_SY, BMPWIN_MAIL_PAL, BMPWIN_MAIL17_CGX
	},
	{
		BMPWIN_MAIL_FRM, BMPWIN_MAIL_PX, BMPWIN_MAIL_PY,
		BMPWIN_MAIL_SX, BMPWIN_MAIL_SY, BMPWIN_MAIL_PAL, BMPWIN_MAIL18_CGX
	},
	{
		BMPWIN_MAIL_FRM, BMPWIN_MAIL_PX, BMPWIN_MAIL_PY,
		BMPWIN_MAIL_SX, BMPWIN_MAIL_SY, BMPWIN_MAIL_PAL, BMPWIN_MAIL19_CGX
	},
	{
		BMPWIN_MAIL_FRM, BMPWIN_MAIL_PX, BMPWIN_MAIL_PY,
		BMPWIN_MAIL_SX, BMPWIN_MAIL_SY, BMPWIN_MAIL_PAL, BMPWIN_MAIL20_CGX
	},

	{	// 選択メール
		BMPWIN_SELMAIL_FRM, BMPWIN_SELMAIL_PX, BMPWIN_SELMAIL_PY,
		BMPWIN_SELMAIL_SX, BMPWIN_SELMAIL_SY, BMPWIN_SELMAIL_PAL, BMPWIN_SELMAIL_CGX
	},
	{	//「やめる」
		BMPWIN_RET_FRM, BMPWIN_RET_PX, BMPWIN_RET_PY,
		BMPWIN_RET_SX, BMPWIN_RET_SY, BMPWIN_RET_PAL, BMPWIN_RET_CGX
	},
	{	//「とじる」
		BMPWIN_CLOSE_FRM, BMPWIN_CLOSE_PX, BMPWIN_CLOSE_PY,
		BMPWIN_CLOSE_SX, BMPWIN_CLOSE_SY, BMPWIN_CLOSE_PAL, BMPWIN_CLOSE_CGX
	},
	{	// ページ
		BMPWIN_PAGE_FRM, BMPWIN_PAGE_PX, BMPWIN_PAGE_PY,
		BMPWIN_PAGE_SX, BMPWIN_PAGE_SY, BMPWIN_PAGE_PAL, BMPWIN_PAGE_CGX
	},

	{	// メッセージ
		BMPWIN_TALK_FRM, BMPWIN_TALK_PX, BMPWIN_TALK_PY,
		BMPWIN_TALK_SX, BMPWIN_TALK_SY, BMPWIN_TALK_PAL, BMPWIN_TALK_CGX
	},

	{	//「メールボックス」
		BMPWIN_TITLE_FRM, BMPWIN_TITLE_PX, BMPWIN_TITLE_PY,
		BMPWIN_TITLE_SX, BMPWIN_TITLE_SY, BMPWIN_TITLE_PAL, BMPWIN_TITLE_CGX
	},
	{	// メールの内容１
		BMPWIN_MAILMSG_FRM, BMPWIN_MAILMSG_PX, BMPWIN_MAILMSG1_PY,
		BMPWIN_MAILMSG_SX, BMPWIN_MAILMSG_SY, BMPWIN_MAILMSG_PAL, BMPWIN_MAILMSG1_CGX
	},
	{	// メールの内容２
		BMPWIN_MAILMSG_FRM, BMPWIN_MAILMSG_PX, BMPWIN_MAILMSG2_PY,
		BMPWIN_MAILMSG_SX, BMPWIN_MAILMSG_SY, BMPWIN_MAILMSG_PAL, BMPWIN_MAILMSG2_CGX
	},
	{	// メールの内容３
		BMPWIN_MAILMSG_FRM, BMPWIN_MAILMSG_PX, BMPWIN_MAILMSG3_PY,
		BMPWIN_MAILMSG_SX, BMPWIN_MAILMSG_SY, BMPWIN_MAILMSG_PAL, BMPWIN_MAILMSG3_CGX
	},
	{	// 作成者名
		BMPWIN_NAME_FRM, BMPWIN_NAME_PX, BMPWIN_NAME_PY,
		BMPWIN_NAME_SX, BMPWIN_NAME_SY, BMPWIN_NAME_PAL, BMPWIN_NAME_CGX
	},
};



//--------------------------------------------------------------------------------------------
/**
 * ＢＭＰ関連初期化
 *
 * @param	syswk	メールボックス画面システムワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void MBBMP_Init( MAILBOX_SYS_WORK * syswk )
{
	u32	i;

	FontProc_LoadFont( FONT_TOUCH, HEAPID_MAILBOX_APP );

	for( i=0; i<MBMAIN_BMPWIN_ID_MAX; i++ ){
		GF_BGL_BmpWinAddEx( syswk->app->bgl, &syswk->app->win[i], &BmpWinData[i] );
	}
}

//--------------------------------------------------------------------------------------------
/**
 * ＢＭＰ関連削除
 *
 * @param	syswk	メールボックス画面システムワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void MBBMP_Exit( MAILBOX_SYS_WORK * syswk )
{
	u32	i;

	for( i=0; i<MBMAIN_BMPWIN_ID_MAX; i++ ){
		GF_BGL_BmpWinDel( &syswk->app->win[i] );
	}

	FontProc_UnloadFont( FONT_TOUCH );
}

//--------------------------------------------------------------------------------------------
/**
 * 文字列表示（バッファ指定）
 *
 * @param	win		BMPWIN
 * @param	str		文字列バッファ
 * @param	x		表示基準Ｘ座標
 * @param	y		表示基準Ｙ座標
 * @param	fnt		フォント
 * @param	col		カラー
 * @param	mode	表示モード
 *
 * @return	none
 *
 * @li	mode = STRPRINT_MODE_LEFT	: 左詰
 * @li	mode = STRPRINT_MODE_RIGHT	: 右詰
 * @li	mode = STRPRINT_MODE_CENTER	: 中央
 */
//--------------------------------------------------------------------------------------------
static void StrPrintCore(
				GF_BGL_BMPWIN * win, STRBUF * str,
				u32 x, u32 y, FONT_TYPE fnt, GF_PRINTCOLOR col, u32 mode )
{
	if( mode == STRPRINT_MODE_RIGHT ){
		x -= FontProc_GetPrintStrWidth( fnt, str, 0 );
	}else if( mode == STRPRINT_MODE_CENTER ){
		x -= ( FontProc_GetPrintStrWidth( fnt, str, 0 ) / 2 );
	}
	GF_STR_PrintColor( win, fnt, str, x, y, MSG_NO_PUT, col, NULL );
}

//--------------------------------------------------------------------------------------------
/**
 * 文字列表示（固定文字列）
 *
 * @param	appwk	メールボックス画面アプリワーク
 * @param	man		メッセージマネージャ
 * @param	winID	BMPWIN ID
 * @param	msgID	文字列ＩＤ
 * @param	x		表示基準Ｘ座標
 * @param	y		表示基準Ｙ座標
 * @param	fnt		フォント
 * @param	col		カラー
 * @param	mode	表示モード
 *
 * @return	none
 *
 * @li	mode = STRPRINT_MODE_LEFT	: 左詰
 * @li	mode = STRPRINT_MODE_RIGHT	: 右詰
 * @li	mode = STRPRINT_MODE_CENTER	: 中央
 */
//--------------------------------------------------------------------------------------------
static void StrPrint(
				MAILBOX_APP_WORK * appwk, MSGDATA_MANAGER * man,
				u32 winID, u32 msgID, u32 x, u32 y, FONT_TYPE fnt, GF_PRINTCOLOR col, u32 mode )
{
	STRBUF * str = MSGMAN_AllocString( man, msgID );

	StrPrintCore( &appwk->win[winID], str, x, y, fnt, col, mode );

	STRBUF_Delete( str );
}

//--------------------------------------------------------------------------------------------
/**
 * 文字列表示（可変文字列）
 *
 * @param	appwk	メールボックス画面アプリワーク
 * @param	man		メッセージマネージャ
 * @param	winID	BMPWIN ID
 * @param	msgID	文字列ＩＤ
 * @param	x		表示基準Ｘ座標
 * @param	y		表示基準Ｙ座標
 * @param	fnt		フォント
 * @param	col		カラー
 * @param	mode	表示モード
 *
 * @return	none
 *
 * @li	mode = STRPRINT_MODE_LEFT	: 左詰
 * @li	mode = STRPRINT_MODE_RIGHT	: 右詰
 * @li	mode = STRPRINT_MODE_CENTER	: 中央
 */
//--------------------------------------------------------------------------------------------
static void ExStrPrint(
				MAILBOX_APP_WORK * appwk, MSGDATA_MANAGER * man,
				u32 winID, u32 msgID, u32 x, u32 y, FONT_TYPE fnt, GF_PRINTCOLOR col, u32 mode )
{
	STRBUF * str = MSGMAN_AllocString( man, msgID );

	WORDSET_ExpandStr( appwk->wset, appwk->expbuf, str );

	StrPrintCore( &appwk->win[winID], appwk->expbuf, x, y, fnt, col, mode );

	STRBUF_Delete( str );
}

//--------------------------------------------------------------------------------------------
/**
 * メール選択ボタンにＢＭＰをセット
 *
 * @param	syswk	メールボックス画面システムワーク
 * @param	frmID	BGWINFRMのID
 * @param	winID	BMPWINのID
 * @param	mailID	メールデータのID
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void MBBMP_MailButtonSet( MAILBOX_SYS_WORK * syswk, u32 frmID, u32 winID, u32 mailID )
{
	GF_BGL_BMPWIN * win;
	MAIL_DATA * md;
	u32	i;

	win = &syswk->app->win[winID];
	md  = syswk->app->mail[mailID];

	STRBUF_SetStringCode( syswk->app->expbuf, MailData_GetWriterName(md) );

	for( i=0; i<BMPWIN_MAIL_SX; i++ ){
		GF_BGL_BmpWinPrint( win, &syswk->app->btn_back_cgx[0x00], 0, 0, 8, 8, 8*i, 0, 8, 8 );
		GF_BGL_BmpWinPrint( win, &syswk->app->btn_back_cgx[0x20], 0, 0, 8, 8, 8*i, 8, 8, 8 );
	}
	if( MailData_GetWriterSex( md ) == 0 ){
		StrPrintCore(
			win, syswk->app->expbuf, 0, 0, FONT_TOUCH, FCOL_TCH_BLN_M01, STRPRINT_MODE_LEFT );
	}else{
		StrPrintCore(
			win, syswk->app->expbuf, 0, 0, FONT_TOUCH, FCOL_TCH_RDN_M01, STRPRINT_MODE_LEFT );
	}

	GF_BGL_BmpWinCgxOn( win );

	// フレームにBMPを貼り付け
	BGWINFRM_BmpWinOn( syswk->app->wfrm, frmID, win );
}

//--------------------------------------------------------------------------------------------
/**
 * デフォルト文字セット
 *
 * @param	syswk	メールボックス画面システムワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void MBBMP_DefaultStrSet( MAILBOX_SYS_WORK * syswk )
{
	// タイトル
	GF_BGL_BmpWinDataFill( &syswk->app->win[MBMAIN_BMPWIN_ID_TITLE], 0 );
	StrPrint(
		syswk->app, syswk->app->mman,
		MBMAIN_BMPWIN_ID_TITLE, msg_title,
		BMPWIN_TITLE_SX*8/2, 0,
		FONT_SYSTEM, FCOL_SYS_BKN_S15, STRPRINT_MODE_CENTER );
	GF_BGL_BmpWinOnVReq( &syswk->app->win[MBMAIN_BMPWIN_ID_TITLE] );

	// やめる
	GF_BGL_BmpWinDataFill( &syswk->app->win[MBMAIN_BMPWIN_ID_RET], 0 );
	StrPrint(
		syswk->app, syswk->app->mman,
		MBMAIN_BMPWIN_ID_RET, msg_return,
		BMPWIN_RET_SX*8/2, 0,
		FONT_TOUCH, FCOL_TCH_BKN_M15, STRPRINT_MODE_CENTER );
	GF_BGL_BmpWinOnVReq( &syswk->app->win[MBMAIN_BMPWIN_ID_RET] );

	// とじる
	GF_BGL_BmpWinDataFill( &syswk->app->win[MBMAIN_BMPWIN_ID_CLOSE], 0 );
	StrPrint(
		syswk->app, syswk->app->mman,
		MBMAIN_BMPWIN_ID_CLOSE, msg_close,
		BMPWIN_CLOSE_SX*8/2, 0,
		FONT_TOUCH, FCOL_TCH_BKN_M15, STRPRINT_MODE_CENTER );
}

//--------------------------------------------------------------------------------------------
/**
 * 「とじる」表示
 *
 * @param	appwk	メールボックス画面アプリワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void MBBMP_ClosePut( MAILBOX_APP_WORK * appwk )
{
	GF_BGL_BmpWinOffVReq( &appwk->win[MBMAIN_BMPWIN_ID_RET] );
	GF_BGL_BmpWinOnVReq( &appwk->win[MBMAIN_BMPWIN_ID_CLOSE] );
}

//--------------------------------------------------------------------------------------------
/**
 * 「やめる」表示
 *
 * @param	appwk	メールボックス画面アプリワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void MBBMP_ReturnPut( MAILBOX_APP_WORK * appwk )
{
	GF_BGL_BmpWinOffVReq( &appwk->win[MBMAIN_BMPWIN_ID_CLOSE] );
	GF_BGL_BmpWinOnVReq( &appwk->win[MBMAIN_BMPWIN_ID_RET] );
}

//--------------------------------------------------------------------------------------------
/**
 * ページ表示
 *
 * @param	syswk	メールボックス画面システムワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void MBBMP_PagePut( MAILBOX_SYS_WORK * syswk )
{
	STRBUF * str;
	u16	px, sx;

	GF_BGL_BmpWinDataFill( &syswk->app->win[MBMAIN_BMPWIN_ID_PAGE], 0 );

	// スラッシュ
	MSGMAN_GetString( syswk->app->mman, msg_page02, syswk->app->expbuf );
	StrPrintCore(
		&syswk->app->win[MBMAIN_BMPWIN_ID_PAGE], syswk->app->expbuf,
		BMPWIN_PAGE_SX*8/2, 0, FONT_SYSTEM, FCOL_SYS_BKN_M15, STRPRINT_MODE_CENTER );

	sx = FontProc_GetPrintStrWidth( FONT_SYSTEM, syswk->app->expbuf, 0 );

	// 現在のページ
	WORDSET_RegisterNumber(
		syswk->app->wset, 0, syswk->sel_page+1, 1, NUMBER_DISPTYPE_LEFT, NUMBER_CODETYPE_DEFAULT );
	str = MSGMAN_AllocString( syswk->app->mman, msg_page01 );
	WORDSET_ExpandStr( syswk->app->wset, syswk->app->expbuf, str );
	STRBUF_Delete( str );
	px = FontProc_GetPrintStrWidth( FONT_SYSTEM, syswk->app->expbuf, 0 );
	StrPrintCore(
		&syswk->app->win[MBMAIN_BMPWIN_ID_PAGE], syswk->app->expbuf,
		BMPWIN_PAGE_SX*8/2-sx/2-px, 0, FONT_SYSTEM, FCOL_SYS_BKN_M15, STRPRINT_MODE_LEFT );

	// ページ数
	WORDSET_RegisterNumber(
		syswk->app->wset, 0, syswk->app->page_max+1, 1, NUMBER_DISPTYPE_LEFT, NUMBER_CODETYPE_DEFAULT );
	str = MSGMAN_AllocString( syswk->app->mman, msg_page01 );
	WORDSET_ExpandStr( syswk->app->wset, syswk->app->expbuf, str );
	STRBUF_Delete( str );
	StrPrintCore(
		&syswk->app->win[MBMAIN_BMPWIN_ID_PAGE], syswk->app->expbuf,
		BMPWIN_PAGE_SX*8/2+sx/2, 0, FONT_SYSTEM, FCOL_SYS_BKN_M15, STRPRINT_MODE_LEFT );

	GF_BGL_BmpWinOnVReq( &syswk->app->win[MBMAIN_BMPWIN_ID_PAGE] );
}

//--------------------------------------------------------------------------------------------
/**
 * 選択されたメールの差出人を単語登録
 *
 * @param	syswk	メールボックス画面システムワーク
 * @param	bufID	登録番号
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void SelMailNameWordSet( MAILBOX_SYS_WORK * syswk, u32 bufID )
{
	STRBUF * str;
	MAIL_DATA * md;

	md  = syswk->app->mail[ syswk->lst_pos ];

	str = STRBUF_Create( BUFLEN_PERSON_NAME, HEAPID_MAILBOX_APP );
	STRBUF_SetStringCode( str, MailData_GetWriterName(md) );
	WORDSET_RegisterWord( syswk->app->wset, 0, str, MailData_GetWriterSex(md), TRUE, PM_LANG );
	STRBUF_Delete( str );
}

//--------------------------------------------------------------------------------------------
/**
 * 会話メッセージセット
 *
 * @param	syswk	メールボックス画面システムワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void TalkMsgWrite( MAILBOX_SYS_WORK * syswk )
{
	GF_BGL_BMPWIN * win = &syswk->app->win[MBMAIN_BMPWIN_ID_TALK];

	GF_BGL_BmpWinDataFill( win, 15 );

	syswk->app->msgID = GF_STR_PrintColor(
							win, FONT_TALK, syswk->app->expbuf, 0, 0,
							CONFIG_GetMsgPrintSpeed( syswk->config ),
							FCOL_TLK_BKW_M14, NULL );
}

//--------------------------------------------------------------------------------------------
/**
 * メール選択時のメッセージ表示
 *
 * @param	syswk	メールボックス画面システムワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void MBBMP_SelectMsgPut( MAILBOX_SYS_WORK * syswk )
{
	STRBUF * str;

	SelMailNameWordSet( syswk, 0 );

	str = MSGMAN_AllocString( syswk->app->mman, msg_message01 );
	WORDSET_ExpandStr( syswk->app->wset, syswk->app->expbuf, str );
	STRBUF_Delete( str );

	TalkMsgWrite( syswk );
}

//--------------------------------------------------------------------------------------------
/**
 * メッセージウィンドウ表示
 *
 * @param	syswk	メールボックス画面システムワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void MBBMP_TalkWinPut( MAILBOX_SYS_WORK * syswk )
{
	BmpTalkWinWrite(
		&syswk->app->win[MBMAIN_BMPWIN_ID_TALK],
		WINDOW_TRANS_OFF, MBMAIN_TALKWIN_CGX_POS, MBMAIN_MBG_PAL_TALKWIN );

	GF_BGL_BmpWinOnVReq( &syswk->app->win[MBMAIN_BMPWIN_ID_TALK] );
}

//--------------------------------------------------------------------------------------------
/**
 * メッセージウィンドウ非表示
 *
 * @param	syswk	メールボックス画面システムワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void MBBMP_TalkWinDel( MAILBOX_SYS_WORK * syswk )
{
	BmpTalkWinClear( &syswk->app->win[MBMAIN_BMPWIN_ID_TALK], WINDOW_TRANS_OFF );
	GF_BGL_LoadScreenV_Req( syswk->app->bgl, MBMAIN_BGF_MSG_M );
}

//--------------------------------------------------------------------------------------------
/**
 * 「メールをけす」メッセージ表示
 *
 * @param	syswk	メールボックス画面システムワーク
 * @param	id		メッセージＩＤ
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void MBBMP_DeleteMsgPut( MAILBOX_SYS_WORK * syswk, u32 id )
{
	switch( id ){
	case MBBMP_DELMSG_ID_CHECK:		//「ないようは　きえて　しまいますが　よろしい　ですか？」
		MSGMAN_GetString( syswk->app->mman, msg_message02, syswk->app->expbuf );
		break;
	case MBBMP_DELMSG_ID_ERASE:		//「ないようを　けしました」
		MSGMAN_GetString( syswk->app->mman, msg_message03, syswk->app->expbuf );
		break;
	case MBBMP_DELMSG_ID_POKE:		//「ポケモンに　もたせますか？」
		MSGMAN_GetString( syswk->app->mman, msg_message04, syswk->app->expbuf );
		break;
	case MBBMP_DELMSG_ID_BAG:		//「ないようを　けした　メールを バッグに　しまいました」
		MSGMAN_GetString( syswk->app->mman, msg_message05, syswk->app->expbuf );
		break;
	case MBBMP_DELMSG_ID_DELETE:	//「バッグが　いっぱいです… メールを　すてました」
		MSGMAN_GetString( syswk->app->mman, msg_message06, syswk->app->expbuf );
		break;
	}
	TalkMsgWrite( syswk );
}


//--------------------------------------------------------------------------------------------
/**
 * メールの内容表示
 *
 * @param	syswk	メールボックス画面システムワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void MBBMP_MailMesPut( MAILBOX_SYS_WORK * syswk )
{
	u32	i;

	for( i=0; i<MAILDAT_MSGMAX; i++ ){
		GF_BGL_BmpWinDataFill( &syswk->app->win[MBMAIN_BMPWIN_ID_MAILMSG1+i], 0 );
		MailMesPut( syswk, MBMAIN_BMPWIN_ID_MAILMSG1+i, i );
		GF_BGL_BmpWinOnVReq( &syswk->app->win[MBMAIN_BMPWIN_ID_MAILMSG1+i] );
	}

	GF_BGL_BmpWinDataFill( &syswk->app->win[MBMAIN_BMPWIN_ID_NAME], 0 );
	STRBUF_SetStringCode(
		syswk->app->expbuf,
		MailData_GetWriterName(syswk->app->mail[syswk->lst_pos]) );
	StrPrintCore(
		&syswk->app->win[MBMAIN_BMPWIN_ID_NAME], syswk->app->expbuf,
		0, 2, FONT_TALK, FCOL_SYS_BKN_S00, STRPRINT_MODE_LEFT );
	GF_BGL_BmpWinOnVReq( &syswk->app->win[MBMAIN_BMPWIN_ID_NAME] );
}

//--------------------------------------------------------------------------------------------
/**
 * メールメッセージ表示
 *
 * @param	syswk	メールボックス画面システムワーク
 * @param	winID	ウィンドウＩＤ
 * @param	msgID	メッセージＩＤ
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void MailMesPut( MAILBOX_SYS_WORK * syswk, u32 winID, u32 msgID )
{
	PMS_DATA * pms;
	STRBUF * str;

	pms = MailData_GetMsgByIndex(
			syswk->app->mail[syswk->lst_pos], msgID );

	if( PMSDAT_IsEnabled( pms ) == FALSE ){
		return;
	}

	str = PMSDAT_ToString( pms, HEAPID_MAILBOX_APP );

	StrPrintCore(
		&syswk->app->win[winID], str,
		0, 0, FONT_TALK, FCOL_SYS_BKN_S00, STRPRINT_MODE_LEFT );

	STRBUF_Delete( str );
}